package com.tuling.consumer;

import com.tuling.DemoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.IOException;


/**
 * Mock 是 Stub 的一个子集，便于在客户端执行调用接口容错逻辑，因经常需要在出现 RpcException (比如网络失败，超时等)时进行容错，如果用 Stub，可能就需要捕获并依赖 RpcException 类，
 * 而用 Mock 就可以不依赖 RpcException，因为它的约定就是只有出现 RpcException 时才执行
 * https://cn.dubbo.apache.org/zh-cn/docsv2.7/user/examples/local-mock/
 */
@EnableAutoConfiguration
public class MockDubboConsumerDemo {


        @Reference(version = "timeout", timeout = 1000, mock = "fail: return 123")
//    @Reference(version = "timeout", mock = "true")
    private DemoService demoService;

    public static void main(String[] args) throws IOException {
        ConfigurableApplicationContext context = SpringApplication.run(MockDubboConsumerDemo.class);

        DemoService demoService = context.getBean(DemoService.class);

        System.out.println((demoService.sayHello("周瑜")));
    }

}
